package com.hualan.sfzy.controller.counselor;


import com.hualan.sfzy.entity.counselor.CounselorGrade;
import com.hualan.sfzy.service.counselor.CounselorGradeService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CounselorGradeController {
    @Autowired
    private CounselorGradeService counselorGradeService;

    @PostMapping("/counselorGrade")
    public Result add(@RequestBody CounselorGrade counselorGrade) {
        int num = counselorGradeService.add(counselorGrade);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorGrade/{id}")
    public Result remove(@PathVariable Integer id) {
        int num = counselorGradeService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorGrade")
    public Result removeBatch(Integer[] ids) {
        int num = counselorGradeService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/counselorGrade")
    public Result edit(@RequestBody CounselorGrade counselorGrade) {
        int num = counselorGradeService.edit(counselorGrade);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/counselorGrade")
    public Result find() {
        List<CounselorGrade> list = counselorGradeService.find();
        return Result.success(list);
    }

    @GetMapping("/counselorGrade/{id}")
    public Result findById(@PathVariable Integer id) {
        CounselorGrade counselorGrade = counselorGradeService.findById(id);
        return Result.success(counselorGrade);
    }

    @GetMapping("/counselorGrade/page")
    public Result findByPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                    CounselorGrade counselorGrade) {
        Map<String, Object> map = counselorGradeService.findByPage(pageNum, pageSize, counselorGrade);
        return Result.success(map);
    }
}
